package com.kclm.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @Author : lvhx
 * @Date: 2025/11/4 16:08
 * @Description:
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
public class SpringConfig {
//    @Value("${jdbc.driver}")
//    private  String driver;
//    @Value("${jdbc.url}")
//    private  String url;
//    @Value("${jdbc.username}")
//    private  String username;
//    @Value("${jdbc.password}")
//    private  String password;
    @Autowired
    private Environment env;

    @Bean
    public DataSource dataSource(){
       DruidDataSource ds = new DruidDataSource();
//       ds.setUrl(url);
//       ds.setDriverClassName(driver);
//       ds.setUsername(username);
//       ds.setPassword(password);
        ds.setUrl(env.getProperty("jdbc.url"));
        ds.setDriverClassName(env.getProperty("jdbc.driver"));
        ds.setUsername(env.getProperty("jdbc.username"));
        ds.setPassword(env.getProperty("jdbc.password"));
       return ds;
    }
    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource){
//        System.out.println("----");
        return  new JdbcTemplate(dataSource);
    }
}
